﻿@using Abp.Application.Services.Dto
@using Abp.Extensions
@using Abp.Timing;
@using AbpZeroTemplate.Web.Areas.AppAreaName.Startup
@model AbpZeroTemplate.Web.Areas.AppAreaName.Models.HostSettings.HostSettingsViewModel
@{
    ViewBag.CurrentPageName = AppAreaNamePageNames.Host.Settings;
}
@section Scripts {
    <script abp-src="/view-resources/Areas/AppAreaName/Views/HostSettings/Index.js" asp-append-version="true"></script>
}

<div class="m-subheader ">
    <div class="row align-items-center">
        <div class="mr-auto col-sm-12 col-md-6">
            <h3 class="m-subheader__title m-subheader__title--separator">
                <span>@L("Settings")</span>
            </h3>
            <span class="m-section__sub">
                @L("SettingsHeaderInfo")
            </span>
        </div>
        <div class="col-sm-12 col-md-6 text-right">
            <button id="SaveAllSettingsButton" class="btn btn-primary blue"><i class="fa fa-floppy-o"></i> @L("SaveAll")</button>
        </div>
    </div>
</div>

<div class="m-content">
    <div class="m-portlet m-portlet--mobile">
        <div class="m-portlet__body">
            <div id="SettingsTabPanel">

                <ul class="nav nav-tabs m-tabs-line" role="tablist">
                    @if (Clock.SupportsMultipleTimezone)
                    {
                        <li class="nav-item m-tabs__item">
                            <a href="#SettingsGeneralTab" class="nav-link m-tabs__link active" data-toggle="tab" role="tab">
                                @L("General")
                            </a>
                        </li>
                    }
                    <li class="nav-item m-tabs__item">
                        <a href="#SettingsTenantManagementTab" class="nav-link m-tabs__link @((!Clock.SupportsMultipleTimezone) ? "active" : "")" data-toggle="tab" role="tab">
                            @L("TenantManagement")
                        </a>
                    </li>
                    <li class="nav-item m-tabs__item">
                        <a href="#SettingsUserManagementTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                            @L("UserManagement")
                        </a>
                    </li>
                    <li class="nav-item m-tabs__item">
                        <a href="#SecurityManagementTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                            @L("Security")
                        </a>
                    </li>
                    <li class="nav-item m-tabs__item">
                        <a href="#SettingsEmailSmtpTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                            @L("EmailSmtp")
                        </a>
                    </li>
                    <li class="nav-item m-tabs__item">
                        <a href="#BillingTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                            @L("Invoice")
                        </a>
                    </li>
                </ul>

                <div class="tab-content">
                    @if (Clock.SupportsMultipleTimezone)
                    {
                        <div class="tab-pane active" id="SettingsGeneralTab" SettingsEmailSmtpTab>
                            <form id="GeneralSettingsForm">
                                <div class="form-group ">
                                    <label for="Timezone">@L("Timezone")</label>
                                    @Html.DropDownList("Timezone", Model.TimezoneItems.Select(i => i.ToSelectListItem()), new { @class = "form-control edited", id = "Timezone" })
                                </div>
                                <div>
                                    @Html.Hidden("TimezoneForComparison", Model.Settings.General.TimezoneForComparison)
                                </div>
                            </form>
                        </div>
                    }

                    <div class="tab-pane  @((!Clock.SupportsMultipleTimezone) ? "active" : "")" id="SettingsTenantManagementTab" SettingsEmailSmtpTab>

                        <form id="TenantManagementSettingsForm">
                            <h5>@L("FormBasedRegistration")</h5>
                            <div class="form-group m-form__group">
                                <label for="Setting_AllowSelfRegistration" class="m-checkbox col-lg-12">
                                    <input id="Setting_AllowSelfRegistration" type="checkbox" name="AllowSelfRegistration" value="true" @(Model.Settings.TenantManagement.AllowSelfRegistration ? "checked=\"checked\"" : "")>
                                    @L("AllowTenantsToRegisterThemselves")
                                    <span></span>
                                </label>
                                <span class="m-form__help">@L("AllowTenantsToRegisterThemselves_Hint")</span>
                            </div>
                            <div class="form-group m-form__group">
                                <label for="Setting_IsNewRegisteredTenantActiveByDefault" class="m-checkbox col-lg-12">
                                    <input id="Setting_IsNewRegisteredTenantActiveByDefault" type="checkbox" name="IsNewRegisteredTenantActiveByDefault" value="true" @(Model.Settings.TenantManagement.IsNewRegisteredTenantActiveByDefault ? "checked=\"checked\"" : "")>
                                    @L("NewRegisteredTenantsIsActiveByDefault")
                                    <span></span>
                                </label>
                                <span class="m-form__help">@L("NewRegisteredTenantsIsActiveByDefault_Hint")</span>
                            </div>
                            <div class="form-group m-form__group">
                                <label for="Setting_UseCaptchaOnRegistration" class="m-checkbox col-lg-12">
                                    <input id="Setting_UseCaptchaOnRegistration" type="checkbox" name="UseCaptchaOnRegistration" value="true" @(Model.Settings.TenantManagement.UseCaptchaOnRegistration ? "checked=\"checked\"" : "")>
                                    @L("UseCaptchaOnRegistration")
                                    <span></span>
                                </label>
                            </div>
                            <div class="form-group m-form__group">
                                <label for="DefaultEditionId">@L("Edition")</label>
                                @Html.DropDownList("DefaultEditionId", Model.EditionItems.Select(i => i.ToSelectListItem()), new { @class = "form-control edited", id= "DefaultEditionId" })
                            </div>
                        </form>
                    </div>

                    <div class="tab-pane" id="SettingsUserManagementTab" SettingsEmailSmtpTab>
                        <form id="UserManagementSettingsForm">
                            <div class="m-checkbox-list">
                                <label for="Settings_IsEmailConfirmationRequiredForLogin" class="m-checkbox">
                                    <input id="Settings_IsEmailConfirmationRequiredForLogin" type="checkbox" name="IsEmailConfirmationRequiredForLogin" value="true" @(Model.Settings.UserManagement.IsEmailConfirmationRequiredForLogin ? "checked=\"checked\"" : "")>
                                    @L("EmailConfirmationRequiredForLogin")
                                    <span></span>
                                </label>
                                <label for="Settings_SmsVerificationEnabled" class="m-checkbox">
                                    <input id="Settings_SmsVerificationEnabled" type="checkbox" name="SmsVerificationEnabled" value="true" @(Model.Settings.UserManagement.SmsVerificationEnabled ? "checked=\"checked\"" : "")>
                                    @L("SmsVerificationEnabled")
                                    <span></span>
                                </label>
                            </div>
                        </form>
                    </div>

                    <div id="SecurityManagementTab" class="tab-pane" SettingsEmailSmtpTab>
                        <div>
                            <h5>@L("PasswordComplexity")</h5>
                            <label for="Setting_PasswordComplexity_UseDefaultSettings" class="m-checkbox">
                                <input id="Setting_PasswordComplexity_UseDefaultSettings" type="checkbox" name="UseDefaultSettings" value="true" @(Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "checked=\"checked\"" : "")>
                                @L("UseDefaultSettings")
                                <span></span>
                            </label>
                            <hr />
                            <form id="PasswordComplexitySettingsForm" style="@(Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "display:none;" : "")">
                                <div class="m-checkbox-list">
                                    <label for="Setting_PasswordComplexity_RequireDigit" class="m-checkbox">
                                        <input id="Setting_PasswordComplexity_RequireDigit" type="checkbox" name="RequireDigit" value="true" @(Model.Settings.Security.PasswordComplexity.RequireDigit ? "checked=\"checked\"" : "")>
                                        @L("PasswordComplexity_RequireDigit")
                                        <span></span>
                                    </label>
                                    <label for="Setting_PasswordComplexity_RequireLowercase" class="m-checkbox">
                                        <input id="Setting_PasswordComplexity_RequireLowercase" type="checkbox" name="RequireLowercase" value="true" @(Model.Settings.Security.PasswordComplexity.RequireLowercase ? "checked=\"checked\"" : "")>
                                        @L("PasswordComplexity_RequireLowercase")
                                        <span></span>
                                    </label>
                                    <label for="Setting_PasswordComplexity_RequireNonAlphanumeric" class="m-checkbox">
                                        <input id="Setting_PasswordComplexity_RequireNonAlphanumeric" type="checkbox" name="RequireNonAlphanumeric" value="true" @(Model.Settings.Security.PasswordComplexity.RequireNonAlphanumeric ? "checked=\"checked\"" : "")>
                                        @L("PasswordComplexity_RequireNonAlphanumeric")
                                        <span></span>
                                    </label>
                                    <label for="Setting_PasswordComplexity_RequireUppercase" class="m-checkbox">
                                        <input id="Setting_PasswordComplexity_RequireUppercase" type="checkbox" name="RequireUppercase" value="true" @(Model.Settings.Security.PasswordComplexity.RequireUppercase ? "checked=\"checked\"" : "")>
                                        @L("PasswordComplexity_RequireUppercase")
                                        <span></span>
                                    </label>
                                </div>
                                <div class="form-group ">
                                    <label>@L("PasswordComplexity_RequiredLength")</label>
                                    <input type="number" name="RequiredLength" class="form-control edited" value="@Model.Settings.Security.PasswordComplexity.RequiredLength">
                                </div>
                            </form>
                            <form id="DefaultPasswordComplexitySettingsForm" style="@(!Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "display:none;" : "")">
                                <div class="m-checkbox-list">
                                    <label for="Setting_DefaultPasswordComplexity_RequireDigit" class="m-checkbox">
                                        <input id="Setting_DefaultPasswordComplexity_RequireDigit" type="checkbox" name="RequireDigit" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.RequireDigit ? "checked=\"checked\"" : "") disabled>
                                        @L("PasswordComplexity_RequireDigit")
                                        <span></span>
                                    </label>
                                    <label for="Setting_DefaultPasswordComplexity_RequireLowercase" class="m-checkbox">
                                        <input id="Setting_DefaultPasswordComplexity_RequireLowercase" type="checkbox" name="RequireLowercase" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.RequireLowercase ? "checked=\"checked\"" : "") disabled>
                                        @L("PasswordComplexity_RequireLowercase")
                                        <span></span>
                                    </label>
                                    <label for="Setting_DefaultPasswordComplexity_RequireNonAlphanumeric" class="m-checkbox">
                                        <input id="Setting_DefaultPasswordComplexity_RequireNonAlphanumeric" type="checkbox" name="RequireNonAlphanumeric" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.RequireNonAlphanumeric ? "checked=\"checked\"" : "") disabled>
                                        @L("PasswordComplexity_RequireNonAlphanumeric")
                                        <span></span>
                                    </label>
                                    <label for="Setting_DefaultPasswordComplexity_RequireUppercase" class="m-checkbox">
                                        <input id="Setting_DefaultPasswordComplexity_RequireUppercase" type="checkbox" name="RequireUppercase" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.RequireUppercase ? "checked=\"checked\"" : "") disabled>
                                        @L("PasswordComplexity_RequireUppercase")
                                        <span></span>
                                    </label>
                                </div>
                                <div class="form-group">
                                    <label for="RequiredLength">@L("PasswordComplexity_RequiredLength")</label>
                                    <input id="RequiredLength" type="number" name="RequiredLength" class="form-control edited" value="@Model.Settings.Security.DefaultPasswordComplexity.RequiredLength" disabled>
                                </div>
                            </form>
                        </div>

                        <div>
                            <h5>@L("UserLockOut")</h5>
                            <form id="UserLockOutSettingsForm">
                                <label for="Setting_UserLockOut_IsEnabled" class="m-checkbox">
                                    <input id="Setting_UserLockOut_IsEnabled" type="checkbox" name="IsEnabled" value="true" @(Model.Settings.Security.UserLockOut.IsEnabled ? "checked=\"checked\"" : "")>
                                    @L("EnableUserAccountLockingOnFailedLoginAttemts")
                                    <span></span>
                                </label>
                                <div class="form-group">
                                    <label for="MaxFailedAccessAttemptsBeforeLockout">@L("MaxFailedAccessAttemptsBeforeLockout")</label>
                                    <input id="MaxFailedAccessAttemptsBeforeLockout" type="number" name="MaxFailedAccessAttemptsBeforeLockout" class="form-control edited" value="@Model.Settings.Security.UserLockOut.MaxFailedAccessAttemptsBeforeLockout">
                                </div>
                                <div class="form-group">
                                    <label for="DefaultAccountLockoutSeconds">@L("DefaultAccountLockoutDurationAsSeconds")</label>
                                    <input id="DefaultAccountLockoutSeconds" type="number" name="DefaultAccountLockoutSeconds" class="form-control edited" value="@Model.Settings.Security.UserLockOut.DefaultAccountLockoutSeconds">
                                </div>
                            </form>
                        </div>

                        <div>
                            <h5>@L("TwoFactorLogin")</h5>
                            <form id="TwoFactorLoginSettingsForm">
                                <div class="m-checkbox-list">
                                    <label for="Setting_TwoFactorLogin_IsEnabled" class="m-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsEnabled" type="checkbox" name="IsEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsEnabled ? "checked=\"checked\"" : "")>
                                        @L("EnableTwoFactorLogin")
                                        <span></span>
                                    </label>
                                    <label for="Setting_TwoFactorLogin_IsEmailProviderEnabled" class="m-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsEmailProviderEnabled" type="checkbox" name="IsEmailProviderEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsEmailProviderEnabled ? "checked=\"checked\"" : "")>
                                        @L("IsEmailVerificationEnabled")
                                        <span></span>
                                    </label>
                                    <label for="Setting_TwoFactorLogin_IsSmsProviderEnabled" class="m-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsSmsProviderEnabled" type="checkbox" name="IsSmsProviderEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsSmsProviderEnabled ? "checked=\"checked\"" : "")>
                                        @L("IsSmsVerificationEnabled")
                                        <span></span>
                                    </label>
                                    <label for="Setting_TwoFactorLogin_IsGoogleAuthenticatorEnabled" class="m-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsGoogleAuthenticatorEnabled" type="checkbox" name="IsGoogleAuthenticatorEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsGoogleAuthenticatorEnabled ? "checked=\"checked\"" : "")>
                                        @L("IsGoogleAuthenticatorEnabled")
                                        <span></span>
                                    </label>
                                    <label for="Setting_TwoFactorLogin_IsRememberBrowserEnabled" class="m-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsRememberBrowserEnabled" type="checkbox" name="IsRememberBrowserEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsRememberBrowserEnabled ? "checked=\"checked\"" : "")>
                                        @L("AllowToRememberBrowserForTwoFactorLogin")
                                        <span></span>
                                    </label>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="tab-pane" id="SettingsEmailSmtpTab">
                        <form id="EmailSmtpSettingsForm">
                            <div class="form-group">
                                <label for="DefaultFromAddress">@L("DefaultFromAddress")</label>
                                <input id="DefaultFromAddress" type="email" name="DefaultFromAddress" class="form-control@(Model.Settings.Email.DefaultFromAddress.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.DefaultFromAddress" maxlength="@AbpZeroTemplate.Authorization.Users.User.MaxEmailAddressLength">
                            </div>

                            <div class="form-group">
                                <label for="DefaultFromDisplayName">@L("DefaultFromDisplayName")</label>
                                <input id="DefaultFromDisplayName" type="text" name="DefaultFromDisplayName" class="form-control@(Model.Settings.Email.DefaultFromDisplayName.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.DefaultFromDisplayName" maxlength="128">
                            </div>

                            <div class="form-group ">
                                <label for="SmtpHost">@L("SmtpHost")</label>
                                <input id="SmtpHost" type="text" name="SmtpHost" class="form-control@(Model.Settings.Email.SmtpHost.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpHost" maxlength="64">
                            </div>

                            <div class="form-group ">
                                <label for="SmtpPort">@L("SmtpPort")</label>
                                <input id="SmtpPort" type="number" name="SmtpPort" class="form-control edited" value="@Model.Settings.Email.SmtpPort" maxlength="5">
                            </div>

                            <div class="md-checkbox-list">
                                <label for="Settings_SmtpEnableSsl" class="m-checkbox col-lg-12">
                                    <input id="Settings_SmtpEnableSsl" type="checkbox" name="SmtpEnableSsl" value="true" @Html.Raw(Model.Settings.Email.SmtpEnableSsl ? "checked=\"checked\"" : "")>
                                    @L("UseSsl")
                                    <span></span>
                                </label>
                                <label for="Settings_SmtpUseDefaultCredentials" class="m-checkbox">
                                    <input id="Settings_SmtpUseDefaultCredentials" type="checkbox" name="SmtpUseDefaultCredentials" value="true" @Html.Raw(Model.Settings.Email.SmtpUseDefaultCredentials ? "checked=\"checked\"" : "")>
                                    @L("UseDefaultCredentials")
                                    <span></span>
                                </label>
                            </div>

                            <div class="form-group">
                                <label for="SmtpDomain">@L("DomainName")</label>
                                <input id="SmtpDomain" type="text" name="SmtpDomain" class="form-control@(Model.Settings.Email.SmtpDomain.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpDomain" maxlength="128">
                            </div>

                            <div class="form-group">
                                <label for="SmtpUserName">@L("UserName")</label>
                                <input id="SmtpUserName" type="text" name="SmtpUserName" class="form-control@(Model.Settings.Email.SmtpUserName.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpUserName" maxlength="128">
                            </div>

                            <div class="form-group">
                                <label for="SmtpPassword">@L("Password")</label>
                                <input id="SmtpPassword" type="password" name="SmtpPassword" class="form-control@(Model.Settings.Email.SmtpPassword.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpPassword" maxlength="128" autocomplete="off">
                            </div>

                            <hr />

                            <h4>@L("TestEmailSettingsHeader")</h4>

                            <div class="row">
                                <div class="form-group  col-md-4">
                                    <input id="TestEmailAddressInput" type="text" class="form-control input-sm" value="@ViewBag.CurrentUserEmail">
                                </div>
                                <div class="form-group col-md-2">
                                    <button id="SendTestEmailButton" class="btn btn-primary" type="button">@L("SendTestEmail")</button>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="tab-pane" id="BillingTab">
                        <form id="BillingSettingsForm" class="m-form">
                            <div class="form-group">
                                <label for="LegalName">@L("LegalName")</label>
                                <input id="LegalName" type="text" name="LegalName" class="form-control" value="@Model.Settings.Billing.LegalName" maxlength="64">
                            </div>

                            <div class="form-group">
                                <label for="Address">@L("Address")</label>
                                <textarea id="Address" rows="5" name="Address" class="form-control" maxlength="256">@Model.Settings.Billing.Address</textarea>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
